package com.report.utils;

import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;

import java.util.List;

/**
 * @author summer
 * @date 2023-02-16 15:37
 */
public class SendCode {

    public static void main(String[] args) {

        DataSourceConfig.Builder datasourceBuilder = new DataSourceConfig.Builder( "jdbc:mysql://8.152.161.13:3306/sbj-base?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8", "root", "songbojin123456!@#$");
        FastAutoGenerator fastAutoGenerator = FastAutoGenerator.create(datasourceBuilder);
        //, "longTerm", "projectCsdd", "relation", "scale", "school", "shortTerm", "grander"
        List<String> list = ListUtil.list(true,   "member_order","address",
                "bank","buy_goods","coupons","expend","income",
                "member","member_store");
        list.forEach(l->{
            fastAutoGenerator
                    .globalConfig(builder -> {
                        builder.author("summer")// 设置作者
                                .outputDir("/Users/Zhuanz/Desktop/source/java")
                                .commentDate("yyyy/MM/dd HH:mm:ss")
                                .disableOpenDir();
                    })
                    .packageConfig(builder -> builder
                            .parent("com.sbj")
                            .entity("entity")
                    )
                    .strategyConfig(builder -> {
                        builder.addInclude(l)
                                .entityBuilder()
                                .enableLombok()
                                .idType(IdType.AUTO)
                                .enableTableFieldAnnotation()
                                .logicDeleteColumnName("deleted")
                                .addTableFills(new Column("createTime", FieldFill.INSERT))
                                // 	数据库表映射到实体的命名策略 -- 下划线转驼峰命名
                                .naming(NamingStrategy.underline_to_camel);

                    })
                    .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                    .execute();
        });
    }
}
